/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.activity.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.activity.entity.Activity;
import com.jeeplus.modules.activity.entity.ActivityRecord;
import com.jeeplus.modules.oa.entity.OaNotifyRecord;
import com.jeeplus.modules.activity.dao.ActivityDao;
import com.jeeplus.modules.activity.dao.ActivityRecordDao;

/**
 * 活动管理Service
 * @author lw
 * @version 2018-01-14
 */
@Service
@Transactional(readOnly = true)
public class ActivityInfoService extends CrudService<ActivityDao, Activity> {
	
	@Autowired
	private ActivityRecordDao activityRecordDao; 
	
	public Activity get(String id) {
		return super.get(id);
	}
	
	public List<Activity> findList(Activity activity) {
		return super.findList(activity);
	}
	
	public Page<Activity> findPage(Page<Activity> page, Activity activity) {
		return super.findPage(page, activity);
	}
	
	@Transactional(readOnly = false)
	public void save(Activity activity) {
		super.save(activity);
		activityRecordDao.deleteByActId(activity.getId());
		List<ActivityRecord> activityRecordList = activity.getActivityRecordList();
		if(activityRecordList.size()>0) {
			activityRecordDao.insertBatch(activityRecordList);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(Activity activity) {
		super.delete(activity);
	}
	
	public Activity getActRecordList(Activity activity) {
		if(activity.getId() != null &&  activity.getId() != "") {
			activity.setActivityRecordList((activityRecordDao.findList(new ActivityRecord(activity))));
		}
		return activity;
	}
}